﻿// HSS.Interlink.DialogCloseButton.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.html)
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       DialogCloseButton.cs
// Author:     HSS\gbanta
// Created:    07/16/2011
// Modified:   07/22/2011
// ----------------------------------------------------------------------------
using System.Windows.Controls;
using System.Windows.Media;

namespace HSS.Interlink
{
	/// <summary>
	/// DialogCloseButton
	/// </summary>
	public sealed class DialogCloseButton : Button
	{
		Border shader;
		Border buttonColor;
		byte focusedBorderA = 159;
		byte focusedBorderRGB = 0;
		byte unfocusedBorderA = 159;
		byte unfocusedBorderRGB = 112;

		/// <summary>
		/// Constructor
		/// </summary>
		public DialogCloseButton()
		{
			DefaultStyleKey = typeof(DialogCloseButton);
		}
		/// <summary>
		/// Builds the visual tree for the System.Windows.Controls.Button when a new template is applied.
		/// </summary>
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			shader = this.GetTemplateChild("Shade") as Border;
			buttonColor = this.GetTemplateChild("ButtonColor") as Border;
		}

		internal void SetFocusedAppearance()
		{
			if (null != shader)
				shader.Opacity = 1;
			if (null != buttonColor)
				buttonColor.BorderBrush = new SolidColorBrush(Color.FromArgb(focusedBorderA, focusedBorderRGB, focusedBorderRGB, focusedBorderRGB));
		}
		internal void SetUnfocusedAppearance()
		{
			if (null != shader)
				shader.Opacity = 0;
			if (null != buttonColor)
				buttonColor.BorderBrush = new SolidColorBrush(Color.FromArgb(unfocusedBorderA, unfocusedBorderRGB, unfocusedBorderRGB, unfocusedBorderRGB));
		}
	}
}